﻿using BHan.Context;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using System.Windows;

namespace BHan
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// Gets the current <see cref="App"/> instance in use
        /// </summary>
        public new static App Current => (App)Application.Current;

        /// <summary>
        /// Gets the <see cref="IServiceProvider"/> instance to resolve application services.
        /// </summary>
        public IServiceProvider Services{ get;}
        public App()
        {
            Services = ConfigureServices();
            this.InitializeComponent();

        }

        /// <summary>
        /// 批量依赖注入
        /// </summary>
        /// <returns></returns>
        private static IServiceProvider ConfigureServices()
        {
            var services = new ServiceCollection();
            services.AddDbContext<AppDataContext>(ServiceLifetime.Singleton);
            var bhan = Assembly.Load("BHan");
            services.RegisterServicesFromAssembly(bhan);
            return services.BuildServiceProvider();
        }

         
    }

}
